<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {

	public function _initialize()
	{
	    header('Access-Control-Allow-Origin: *');  

        header('Access-Control-Allow-Credentials: true'); 
      
        header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS'); //允许的请求类型
        
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"); 

	}

    public function index(){
        phpinfo();
    }

    public function get_sys_dept_dict_list()
    {
    	$page = I('get.page');
    	$limit = I('get.limit');

    	$data = M('sys_dept_dict')->order('uuid desc')->limit(($page-1)*$limit,$limit)->select();
    	for ($i=0; $i < count($data); $i++) 
    	{ 
    		$info = $data[$i];
    		$data[$i]['dept_date'] = date('Y-m-d H:i:s',$info['dept_date']);
    	}
    	$json['data'] = $data;
    	$json['code'] = 0;
    	$json['count'] = M('sys_dept_dict')->count();
    	$json['msg'] = "";

    	$this->ajaxReturn($json,'json');
    }

    public function get_sys_dept_dict_one()
    {
    	$uuid = I('post.uuid');

    	$info = M('sys_dept_dict')->where("uuid = '$uuid'")->find();
    	$info['dept_date'] = date('Y-m-d H:i:s',$info['dept_date']);
    	$json['data'] 	= $info;
    	$json['code'] 	= 0;
    	$json['msg'] 	= "";

    	$this->ajaxReturn($json,'json');
    }

    public function save_sys_dept_dict_one()
    {
    	$data = I('post.');
    	$uuid = $data['uuid'];
    	unset($data['uuid']);

    	$result = M('sys_dept_dict')->where("uuid = '$uuid'")->save($data);
    	if($result !== false)
    	{
    		$json['code'] = 0;
    		$json['msg'] = "修改成功";
    	}
    	else
    	{
    		$json['code'] = -1;
    		$json['msg'] = "修改失败";
    	}
 
    	$this->ajaxReturn($json,'json');
    }

    public function add_sys_dept_dict_one()
    {
    	$data = I('post.');
    	$uuid = uuid();
    	$data['uuid'] = $uuid;
    	$data['dept_date'] = time();
    	$result = M('sys_dept_dict')->add($data);
    	if($result !== false)
    	{
    		$json['code'] = 0;
    		$json['msg'] = "添加成功";
    	}
    	else
    	{
    		$json['code'] = -1;
    		$json['msg'] = "添加失败";
    	}
 
    	$this->ajaxReturn($json,'json');
    }

    /*sys_dept_info*/
    public function get_sys_dept_info_list()
    {
        $page = I('get.page');
        $limit = I('get.limit');

        $data = M('sys_dept_info')->order('uuid desc')->limit(($page-1)*$limit,$limit)->select();
        for ($i=0; $i < count($data); $i++) 
        { 
            $info = $data[$i];
            $data[$i]['dept_date'] = date('Y-m-d H:i:s',$info['dept_date']);
        }
        $json['data'] = $data;
        $json['code'] = 0;
        $json['count'] = M('sys_dept_info')->count();
        $json['msg'] = "";
        
        $this->ajaxReturn($json,'json');
    }

    public function get_sys_dept_info_one()
    {
        $uuid = I('post.uuid');

        $info = M('sys_dept_info')->where("uuid = '$uuid'")->find();
        $info['dept_date'] = date('Y-m-d H:i:s',$info['dept_date']);
        $json['data']   = $info;
        $json['code']   = 0;
        $json['msg']    = "";

        $this->ajaxReturn($json,'json');
    }

    public function save_sys_dept_info_one()
    {
        $data = I('post.');
        $uuid = $data['uuid'];
        unset($data['uuid']);

        $result = M('sys_dept_info')->where("uuid = '$uuid'")->save($data);
        if($result !== false)
        {
            $json['code'] = 0;
            $json['msg'] = "修改成功";
        }
        else
        {
            $json['code'] = -1;
            $json['msg'] = "修改失败";
        }
 
        $this->ajaxReturn($json,'json');
    }

    public function add_sys_dept_info_one()
    {
        $data = I('post.');
        $uuid = uuid();
        $data['uuid'] = $uuid;
        $data['dept_date'] = time();
        $result = M('sys_dept_info')->add($data);
        if($result !== false)
        {
            $json['code'] = 0;
            $json['msg'] = "添加成功";
        }
        else
        {
            $json['code'] = -1;
            $json['msg'] = "添加失败";
        }
 
        $this->ajaxReturn($json,'json');
    }

    /*set_accountdepttype*/
    public function get_set_accountdepttype_list()
    {
        $page = I('get.page');
        $limit = I('get.limit');

        $data = M('set_accountdepttype')->order('uuid desc')->limit(($page-1)*$limit,$limit)->select();
        $json['data'] = $data;
        $json['code'] = 0;
        $json['count'] = M('set_accountdepttype')->count();
        $json['msg'] = "";

        $this->ajaxReturn($json,'json');
    }

    public function get_set_accountdepttype_one()
    {
        $uuid = I('post.uuid');

        $info = M('set_accountdepttype')->where("uuid = '$uuid'")->find();
        $json['data']   = $info;
        $json['code']   = 0;
        $json['msg']    = "";

        $this->ajaxReturn($json,'json');
    }

    public function save_set_accountdepttype_one()
    {
        $data = I('post.');
        $uuid = $data['uuid'];
        unset($data['uuid']);

        $result = M('set_accountdepttype')->where("uuid = '$uuid'")->save($data);
        if($result !== false)
        {
            $json['code'] = 0;
            $json['msg'] = "修改成功";
        }
        else
        {
            $json['code'] = -1;
            $json['msg'] = "修改失败";
        }
 
        $this->ajaxReturn($json,'json');
    }

    public function add_set_accountdepttype_one()
    {
        $data = I('post.');
        $uuid = uuid();
        $data['uuid'] = $uuid;
        $result = M('set_accountdepttype')->add($data);
        if($result !== false)
        {
            $json['code'] = 0;
            $json['msg'] = "添加成功";
        }
        else
        {
            $json['code'] = -1;
            $json['msg'] = "添加失败";
        }
 
        $this->ajaxReturn($json,'json');
    }

    /*cbhs_dept_cost_detail*/
    public function get_cbhs_dept_cost_detail_list()
    {
    	$page = I('get.page');
    	$limit = I('get.limit');

    	$data = M('cbhs_dept_cost_detail')->limit(($page-1)*$limit,$limit)->select();
    	for ($i=0; $i < count($data); $i++) 
    	{ 
    		$info = $data[$i];
    		$data[$i]['accounting_date'] = date('Y-m-d H:i:s',$info['accounting_date']);
    		$data[$i]['operator_date'] = date('Y-m-d H:i:s',$info['operator_date']);
    	}
    	$json['data'] = $data;
    	$json['code'] = 0;
    	$json['count'] = M('cbhs_dept_cost_detail')->count();
    	$json['msg'] = "";

    	$this->ajaxReturn($json,'json');
    }

    public function get_cbhs_dept_cost_detail_one()
    {
    	$uuid = I('post.uuid');

    	$info = M('cbhs_dept_cost_detail')->where("uuid = '$uuid'")->find();
    	$info['accounting_date'] = date('Y-m-d H:i:s',$info['accounting_date']);
    	$info['operator_date'] = date('Y-m-d H:i:s',$info['operator_date']);
    	$json['data'] 	= $info;
    	$json['code'] 	= 0;
    	$json['msg'] 	= "";

    	$this->ajaxReturn($json,'json');
    }

    public function save_cbhs_dept_cost_detail_one()
    {
    	$data = I('post.');
    	$uuid = $data['uuid'];
    	unset($data['uuid']);

    	$result = M('cbhs_dept_cost_detail')->where("uuid = '$uuid'")->save($data);
    	if($result !== false)
    	{
    		$json['code'] = 0;
    		$json['msg'] = "修改成功";
    	}
    	else
    	{
    		$json['code'] = -1;
    		$json['msg'] = "修改失败";
    	}
 
    	$this->ajaxReturn($json,'json');
    }

    public function add_cbhs_dept_cost_detail_one()
    {
    	$data = I('post.');
    	$uuid = uuid();
    	$data['uuid'] = $uuid;
    	$result = M('cbhs_dept_cost_detail')->add($data);
    	if($result !== false)
    	{
    		$json['code'] = 0;
    		$json['msg'] = "添加成功";
    	}
    	else
    	{
    		$json['code'] = -1;
    		$json['msg'] = "添加失败";
    	}
 
    	$this->ajaxReturn($json,'json');
    }


     


    /*new_staff_info*/
    public function get_new_staff_info_list()
    {
    	$page = I('get.page');
    	$limit = I('get.limit');

    	$data = M('new_staff_info')->limit(($page-1)*$limit,$limit)->select();
    	for ($i=0; $i < count($data); $i++) 
    	{ 
    		$info = $data[$i];
    	}
    	$json['data'] = $data;
    	$json['code'] = 0;
    	$json['count'] = M('new_staff_info')->count();
    	$json['msg'] = "";

    	$this->ajaxReturn($json,'json');
    }

    public function get_new_staff_info_one()
    {
    	$uuid = I('post.uuid');

    	$info = M('new_staff_info')->where("uuid = '$uuid'")->find();
    	$json['data'] 	= $info;
    	$json['code'] 	= 0;
    	$json['msg'] 	= "";

    	$this->ajaxReturn($json,'json');
    }

    public function save_new_staff_info_one()
    {
    	$data = I('post.');
    	$uuid = $data['uuid'];
    	unset($data['uuid']);

    	$result = M('new_staff_info')->where("uuid = '$uuid'")->save($data);
    	if($result !== false)
    	{
    		$json['code'] = 0;
    		$json['msg'] = "修改成功";
    	}
    	else
    	{
    		$json['code'] = -1;
    		$json['msg'] = "修改失败";
    	}
 
    	$this->ajaxReturn($json,'json');
    }

    public function add_new_staff_info_one()
    {
    	$data = I('post.');
    	$uuid = uuid();
    	$data['uuid'] = $uuid;
    	$result = M('new_staff_info')->add($data);
    	if($result !== false)
    	{
    		$json['code'] = 0;
    		$json['msg'] = "添加成功";
    	}
    	else
    	{
    		$json['code'] = -1;
    		$json['msg'] = "添加失败";
    	}
 
    	$this->ajaxReturn($json,'json');
    }


    /*set_checkbonusdays*/
    public function get_set_checkbonusdays_list()
    {
    	$page = I('get.page');
    	$limit = I('get.limit');

    	$data = M('set_checkbonusdays')->limit(($page-1)*$limit,$limit)->select();
    	for ($i=0; $i < count($data); $i++) 
    	{ 
    		$info = $data[$i];
    	}
    	$json['data'] = $data;
    	$json['code'] = 0;
    	$json['count'] = M('set_checkbonusdays')->count();
    	$json['msg'] = "";

    	$this->ajaxReturn($json,'json');
    }

    public function get_set_checkbonusdays_one()
    {
    	$uuid = I('post.uuid');

    	$info = M('set_checkbonusdays')->where("uuid = '$uuid'")->find();
    	$json['data'] 	= $info;
    	$json['code'] 	= 0;
    	$json['msg'] 	= "";

    	$this->ajaxReturn($json,'json');
    }

    public function save_set_checkbonusdays_one()
    {
    	$data = I('post.');
    	$uuid = $data['uuid'];
    	unset($data['uuid']);

    	$result = M('set_checkbonusdays')->where("uuid = '$uuid'")->save($data);
    	if($result !== false)
    	{
    		$json['code'] = 0;
    		$json['msg'] = "修改成功";
    	}
    	else
    	{
    		$json['code'] = -1;
    		$json['msg'] = "修改失败";
    	}
 
    	$this->ajaxReturn($json,'json');
    }

    public function add_set_checkbonusdays_one()
    {
    	$data = I('post.');
    	$uuid = uuid();
    	$data['uuid'] = $uuid;
    	$result = M('set_checkbonusdays')->add($data);
    	if($result !== false)
    	{
    		$json['code'] = 0;
    		$json['msg'] = "添加成功";
    	}
    	else
    	{
    		$json['code'] = -1;
    		$json['msg'] = "添加失败";
    	}
 
    	$this->ajaxReturn($json,'json');
    }

    /*guide_gather_code*/
    public function get_guide_gather_code_list()
    {
    	$page = I('get.page');
    	$limit = I('get.limit');

    	$data = M('guide_gather_code')->limit(($page-1)*$limit,$limit)->select();
    	for ($i=0; $i < count($data); $i++) 
    	{ 
    		$info = $data[$i];
    	}
    	$json['data'] = $data;
    	$json['code'] = 0;
    	$json['count'] = M('guide_gather_code')->count();
    	$json['msg'] = "";

    	$this->ajaxReturn($json,'json');
    }

    public function get_guide_gather_code_one()
    {
    	$uuid = I('post.uuid');

    	$info = M('guide_gather_code')->where("uuid = '$uuid'")->find();
    	$json['data'] 	= $info;
    	$json['code'] 	= 0;
    	$json['msg'] 	= "";

    	$this->ajaxReturn($json,'json');
    }

    public function save_guide_gather_code_one()
    {
    	$data = I('post.');
    	$uuid = $data['uuid'];
    	unset($data['uuid']);

    	$result = M('guide_gather_code')->where("uuid = '$uuid'")->save($data);
    	if($result !== false)
    	{
    		$json['code'] = 0;
    		$json['msg'] = "修改成功";
    	}
    	else
    	{
    		$json['code'] = -1;
    		$json['msg'] = "修改失败";
    	}
 
    	$this->ajaxReturn($json,'json');
    }

    public function add_guide_gather_code_one()
    {
    	$data = I('post.');
    	$uuid = uuid();
    	$data['uuid'] = $uuid;
    	$result = M('guide_gather_code')->add($data);
    	if($result !== false)
    	{
    		$json['code'] = 0;
    		$json['msg'] = "添加成功";
    	}
    	else
    	{
    		$json['code'] = -1;
    		$json['msg'] = "添加失败";
    	}
 
    	$this->ajaxReturn($json,'json');
    }

    public function create_index_file()
    {
    	$addfile = fopen("H:/phpstudy/PHPTutorial/WWW/jixiao_html/X-admin/html/test/index.html", "w");
    	$addtext_top = '<!DOCTYPE html>
						<html class="x-admin-sm">
							<head>
								<meta charset="UTF-8">
								<title>欢迎页面-X-admin2.2</title>
								<meta name="renderer" content="webkit">
								<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
								<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
								<link rel="stylesheet" href="../../css/font.css">
								<link rel="stylesheet" href="../../css/xadmin.css">
								<script type="text/javascript" src="../../lib/layui/layui.js" charset="utf-8"></script>
								<script type="text/javascript" src="../../js/xadmin.js"></script>
								<script src="../../js/base.js" type="text/javascript" charset="utf-8"></script>
								<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
								<!--[if lt IE 9]>
						            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
						            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
						        <![endif]-->
							</head>

							<body>
								<div class="layui-fluid">
									<div class="layui-row">
										<form class="layui-form" lay-filter="example">
											<div class="layui-form-item">
												<input type="hidden" id="uuid" name="uuid" required="" autocomplete="off" class="layui-input">';

		$col_arr = array();
		$col_arr['guide_gather_code'] = '指标集代码';
		$col_arr['guide_gather_name'] = '指标集名称';
		$col_arr['guide_attr'] = '指标集属性';
		$col_arr['organ_class'] = '组织分类';
		$col_arr['evaluation_year'] = '指标集年度';
		$table = "guide_gather_class";
		$tablename = "KPI指标集设置";
		$addtext_center = "";

		foreach ($col_arr as $key => $value) 
		{
			$addtext_center.='<div class="layui-form-item">
							<label for="L_username" class="layui-form-label">
								<span class="x-red">*</span>'.$value.'</label>
							<div class="layui-input-inline">
								<input type="text" id="'.$key.'" name="'.$key.'" required="" autocomplete="off" class="layui-input">
							</div>
						</div>';
		}

		$addtext_bottom = '<div class="layui-form-item">
							<label for="L_repass" class="layui-form-label"></label>
							<button class="layui-btn" lay-filter="add" lay-submit="">添加</button>
						</div>
				</form>
			</div>
		</div>
		<script>
			layui.use(["form", "layer"],
				function() {
					$ = layui.jquery;
					var form = layui.form,
						layer = layui.layer;
					

					//监听提交
					form.on("submit(add)",
						function(data) {
							console.log(data.field);
							
							$.post(root+"add_'.$table.'_one",
							data.field,
							function(data){
								if(data.code == 0)
								{
									layer.alert(data.msg, {
										icon: 6
									});
									
									xadmin.close();
									
									// 可以对父窗口进行刷新 
									xadmin.father_reload();
								}
								else
								{
									layer.alert(data.msg, {
										icon: 2
									});
								}
							});
							
							return false;
						});
				});
		</script>
		<script>
			var _hmt = _hmt || [];
			(function() {
				var hm = document.createElement("script");
				hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
				var s = document.getElementsByTagName("script")[0];
				s.parentNode.insertBefore(hm, s);
			})();
		</script>
	</body>

</html>';
		$txt = $addtext_top.$addtext_center.$addtext_bottom;
		fwrite($addfile, $txt);
		fclose($addfile);
    }

    public function create_edit_file()
    {

    }

    public function create_add_file()
    {
    	$addfile = fopen("H:/phpstudy/PHPTutorial/WWW/jixiao_html/X-admin/html/test/add.html", "w");
    	$addtext_top = '<!DOCTYPE html>
						<html class="x-admin-sm">
							<head>
								<meta charset="UTF-8">
								<title>欢迎页面-X-admin2.2</title>
								<meta name="renderer" content="webkit">
								<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
								<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
								<link rel="stylesheet" href="../../css/font.css">
								<link rel="stylesheet" href="../../css/xadmin.css">
								<script type="text/javascript" src="../../lib/layui/layui.js" charset="utf-8"></script>
								<script type="text/javascript" src="../../js/xadmin.js"></script>
								<script src="../../js/base.js" type="text/javascript" charset="utf-8"></script>
								<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
								<!--[if lt IE 9]>
						            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
						            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
						        <![endif]-->
							</head>

							<body>
								<div class="layui-fluid">
									<div class="layui-row">
										<form class="layui-form" lay-filter="example">
											<div class="layui-form-item">
												<input type="hidden" id="uuid" name="uuid" required="" autocomplete="off" class="layui-input">';

		$col_arr = array();
		$col_arr['guide_gather_code'] = '指标集代码';
		$col_arr['guide_gather_name'] = '指标集名称';
		$col_arr['guide_attr'] = '指标集属性';
		$col_arr['organ_class'] = '组织分类';
		$col_arr['evaluation_year'] = '指标集年度';
		$table = "guide_gather_class";
		$addtext_center = "";

		foreach ($col_arr as $key => $value) 
		{
			$addtext_center.='<div class="layui-form-item">
							<label for="L_username" class="layui-form-label">
								<span class="x-red">*</span>'.$value.'</label>
							<div class="layui-input-inline">
								<input type="text" id="'.$key.'" name="'.$key.'" required="" autocomplete="off" class="layui-input">
							</div>
						</div>';
		}

		$addtext_bottom = '<div class="layui-form-item">
							<label for="L_repass" class="layui-form-label"></label>
							<button class="layui-btn" lay-filter="add" lay-submit="">添加</button>
						</div>
				</form>
			</div>
		</div>
		<script>
			layui.use(["form", "layer"],
				function() {
					$ = layui.jquery;
					var form = layui.form,
						layer = layui.layer;
					

					//监听提交
					form.on("submit(add)",
						function(data) {
							console.log(data.field);
							
							$.post(root+"add_'.$table.'_one",
							data.field,
							function(data){
								if(data.code == 0)
								{
									layer.alert(data.msg, {
										icon: 6
									});
									
									xadmin.close();
									
									// 可以对父窗口进行刷新 
									xadmin.father_reload();
								}
								else
								{
									layer.alert(data.msg, {
										icon: 2
									});
								}
							});
							
							return false;
						});
				});
		</script>
		<script>
			var _hmt = _hmt || [];
			(function() {
				var hm = document.createElement("script");
				hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
				var s = document.getElementsByTagName("script")[0];
				s.parentNode.insertBefore(hm, s);
			})();
		</script>
	</body>

</html>';
		$txt = $addtext_top.$addtext_center.$addtext_bottom;
		fwrite($addfile, $txt);
		fclose($addfile);

    }


    public function table_delete()
    {
    	$data = I('post.');
    	$table = $data['table'];
    	$uuid = $data['uuid'];

    	$result = M($table)->where("uuid = '$uuid'")->delete();
    	if($result !== false)
    	{
    		$json['code'] = 0;
    		$json['msg'] = "删除成功";
    	}
    	else
    	{
    		$json['code'] = -1;
    		$json['msg'] = "删除失败";
    	}
 
    	$this->ajaxReturn($json,'json');
    }

}